<?php


namespace support\bootstrap;

use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\Common\Annotations\FileCacheReader;
use Webman\Bootstrap;
use Workerman\Worker;

/**
 * 注解扫描
 */
class Annotation implements Bootstrap
{
    /**
     * @var FileCacheReader
     */
    protected static $instance = null;

    public static function start($worker)
    {
        AnnotationRegistry::registerAutoloadNamespace('support\annotation');
        $whitelist = [
            "after", "afterClass", "backupGlobals", "backupStaticAttributes", "before", "beforeClass", "codeCoverageIgnore*",
            "covers", "coversDefaultClass", "coversNothing", "dataProvider", "depends", "doesNotPerformAssertions",
            "expectedException", "expectedExceptionCode", "expectedExceptionMessage", "expectedExceptionMessageRegExp", "group",
            "large", "medium", "preserveGlobalState", "requires", "runTestsInSeparateProcesses", "runInSeparateProcess", "small",
            "test", "testdox", "testWith", "ticket", "uses"
        ];
        foreach ($whitelist as $v) {
            AnnotationReader::addGlobalIgnoredName($v);
        }
        self::$instance = new FileCacheReader(new AnnotationReader(), runtime_path() . "/annotation", env('APP_DEBUG', false));
    }

    public static function instance()
    {
        return self::$instance;
    }
}
